﻿namespace Leetcode.N0396;

public class Solution
{
    public int MaxRotateFunction(int[] nums)
    {
        var sum = nums.Sum(n => n);
        var curSum = 0;
        for (int i = 0; i < nums.Length; i++)
        {
            curSum += nums[i] * i;
        }

        var maxSum = curSum;

        for (int i = 1; i < nums.Length; i++)
        {
            curSum = curSum - nums[nums.Length - i] * nums.Length + sum;
            maxSum = Math.Max(maxSum, curSum);
        }
        return maxSum;
    }
}